﻿/// <reference path="tfcore.js"/>
// #pragma NoCompStart
/*
appmain.js  1.0
specific javascript function for the Triad MainMenu page ONLY!
*/
// #pragma NoCompEnd
_TF = top;
//NameSpaces defined
//APP = {};
_TF.APP.Main = {};
_TF.APP.Global = {};
_TF.APP.Enum = {};

if (typeof _TF.Session === "undefined") { _TF.Session = {}; }

_TF.APP.Enum.alertTypes = { Error: 1, Warning: 2, Information: 3 };
_TF.APP.Enum.locTypes = { NW: 1, N: 2, NE: 3, E: 4, SE: 5, S: 6, SW: 7, W: 8, CEN: 9 };
_TF.APP.Enum.contentTypes = { iframe: 1, html: 2, alert: 3, MsgBox: 4 };
_TF.APP.Enum.msgboxType = { ok: 1, yes: 2, yesno: 3, yesnocancel: 4 };

_TF.APP.Global.CurSearchPage = '';
_TF.APP.Global.SearchPage = '';
_TF.APP.Global.P_Popup = []; // Array to hold modal popup instances
_TF.APP.Global.P_I = 0; // Popup Iteration
_TF.APP.Global.P_Alert = []; // Array to hold Alert instances
_TF.APP.Global.P_AI = 0; // Alert Iteration
_TF.APP.Global.P_MsgBox;
_TF.APP.Global.V_Width = 900;
_TF.APP.Global.V_Height = 700;
_TF.APP.Global.M_Width = 225;
_TF.APP.Global.M_Bar;
_TF.APP.Global.M_Div;
_TF.APP.Global.S_msTillPopup;
_TF.APP.Global.S_Warning;
_TF.APP.Global.S_Interval;
_TF.APP.Global.S_CtDn = 0;
_TF.APP.Global.S_curSecs = 0;
_TF.APP.Global.S_Timeout = _TF.Util.getUrlParam("timeout") ? _TF.getUrlParam("timeout") : 58; // in Minutes
_TF.APP.Global.g_jsErrorTxt = '';
_TF.APP.Global.g_jsErrorType;

_TF.APP.Global.cPage;

_TF.APP.Global.M_hidden = true;
_TF.APP.Global.M_pinned = true;
_TF.APP.Global.pressed_keys = "";

_TF.APP.Global.g_jsSearchButton;
_TF.APP.Global._fwPgTitle = "App Main";



// Firefox requirements - runs immediately.
//---------------------
if (typeof window.innerWidth != 'undefined') {
    HTMLElement.prototype.click = function() {
        var evt = document.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
    };
}

_TF.APP.Main.ClearMem = function() {
    _TF.APP.Global.M_Bar = null;
    _TF.APP.Global.M_Div = null;
    _TF.APP.Global.g_jsSearchButton = null;
    _TF.APP.Global.g_iSTimeOut = null;
};

// Main Menu Functions
//---------------------

_TF.APP.Main.ShowMenu = function() {
    if (!_TF.Element.really_over(_gE("lh-col")) || !_TF.APP.Global.M_hidden) { return; }
    var theImage = _gE('theDockPanelImage');
    document.body.scrollIntoView(true);
    if (_TF.APP.Global.M_hidden && !_TF.APP.Global.M_pinned) {
        var theMainMenuTitle = _gE('theMainMenuTitle');
        theMainMenuTitle.innerText = _TF.APP.Global._fwPgTitle;

        var theMenuTable = _gE('MenuTable');
        theMenuTable.style.backgroundImage = "url(" + _TF.ControlDir + "../images/onyxBar.gif)";
        theMenuTable.style.backgroundRepeat = "repeat-x";

        _TF.APP.Global.M_Width = 225;
        $('#lh-col').width("225px"); // +'px';
        $('#wb').show();
        theImage.src = '/_fw/images/unpinned.gif';
        _TF.APP.Global.cPage.style.width = (_TF.APP.Global.V_Width - _TF.APP.Global.M_Width) + "px";
        _TF.APP.Global.cPage.style.left = _TF.APP.Global.M_Width;
        _TF.APP.Global.M_hidden = false;
    }
    else {
        theImage.src = '/_fw/images/pinned.gif';
    }
};

_TF.APP.Main.HideMenu = function() {
    if (!_TF.Element.really_out(_gE("lh-col"))) { return; }
    document.body.scrollIntoView(true);
    if (!_TF.APP.Global.M_hidden && !_TF.APP.Global.M_pinned) {
        var theMainMenuTitle = _gE('theMainMenuTitle');
        var theImage = _gE('theDockPanelImage');
        var theMenuTable = _gE('MenuTable');
        _TF.APP.Global.M_Width = 15;
        $('#lh-col').width("15px");

        theMenuTable.style.backgroundImage = "url(/_fw/images/toggle_bg_hor.gif)";
        theMenuTable.style.backgroundRepeat = "repeat-y";
        //        theMenuTable.style.height = _TF.APP.Global.M_Div.style.height;

        $('#wb').hide();
        //_TF.APP.Global.M_Bar.style.display = 'none';
        theMainMenuTitle.innerText = "  M A I N  -  M E N U";
        theImage.src = '/_fw/images/trans.gif';

        _TF.APP.Global.cPage.style.width = (_TF.APP.Global.V_Width - _TF.APP.Global.M_Width) + "px";
        _TF.APP.Global.cPage.style.left = _TF.APP.Global.M_Width;
        _TF.APP.Global.M_hidden = true;
    }
};

_TF.APP.Main.pinTheMenu = function() {
    _TF.APP.Global.M_pinned = !_TF.APP.Global.M_pinned;
    var theImage = _gE('theDockPanelImage');
    if (_TF.APP.Global.M_pinned) { theImage.src = '/_fw/images/pinned.gif'; }
    else { theImage.src = '/_fw/images/unpinned.gif'; }
    return false;
};

_TF.APP.Main.onResizeEnd = function() {
    _TF.APP.Global.M_Bar = _gE('wb');
    _TF.APP.Global.M_Div = _gE('lh-col');
    document.body.scrollIntoView(true);
    _TF.APP.Global.V_Height = getViewPortHeight();
    _TF.APP.Global.V_Width = getViewPortWidth();
    document.body.style.height = _TF.APP.Global.V_Height + "px";
    _TF.APP.Global.M_Bar.style.height = _TF.APP.Global.V_Height - 94 + "px";
    var theMenuTable = _gE('MenuTable');

    _TF.APP.Global.cPage.style.height = _TF.APP.Global.V_Height - 68 + "px";
    _TF.APP.Global.M_Div.style.height = _TF.APP.Global.cPage.style.height;
    theMenuTable.style.height = _TF.APP.Global.cPage.style.height;

    _TF.APP.Global.cPage.style.width = _TF.APP.Global.V_Width - _TF.APP.Global.M_Width + "px";
    _TF.APP.Global.cPage.style.left = _TF.APP.Global.M_Width + "px";
};


_TF.APP.Main.RedirectContent = function(strURL) {
    _TF.APP.Global.cPage.src = strURL;
};

OpenUnitTest = function(strTask, strOpId, strOpNum, strMeasurementTable) {
    var strURL = "/Views/UnitTestInspection/ScanIn.aspx?Tsk=" + strTask + "&OpId=" + strOpId + "&OpNum=" + strOpNum + "&MTable=" + strMeasurementTable;
    RedirectContent(strURL);
};

_TF.APP.Main.RefreshContent = function() {
    _gE("ifMainContent").src = _gE("ifMainContent").src;
};

// Dialog Functions
//---------------------
_TF.APP.Main.OpenSearchDialog = function(strSrchPage) {
    var sTitle;
    if (strSrchPage.length > 1) {
        if (strSrchPage == "UnitSetup") { sTitle = "Unit Setup Search"; }
        else {
            sTitle = "Product Setup Search";
        }

        _TF.APP.Global.P_Popup[_TF.APP.Global.P_I] = new _Dialog({ id: '',
            'width': _TF.APP.Global.V_Width - 80, 'height': _TF.APP.Global.V_Height - 60,
            'loc': _TF.APP.Enum.locTypes.CEN, 'type': _TF.APP.Enum.contentTypes.iframe, 'modal': true,
            'title': sTitle, 'URL': '/Views/' + strSrchPage + '/NewSearch.aspx'
        });
        _TF.APP.Global.P_Popup[_TF.APP.Global.P_I].show();
        _TF.APP.Global.P_I += 1;
    }
    else {
        alert("No Search defined for current page.");
    }
};

_TF.APP.Main.OpenSourceDialog = function(myLocation) {
    var protocol = myLocation.protocol;
    var path = myLocation.pathname;
    var file = path.substring(path.lastIndexOf('/') + 1);

    if (file.length > 1) { showModalDlg('/admin/PublishCode/SrcViewer/SrcView.aspx?path=' + path + '&file=' + file, null, _TF.APP.Global.V_Width - 80, _TF.APP.Global.V_Height - 60, "CEN", true, false); }
    else { alert("Invalid filepath: " + file); }
};

_TF.APP.Main.openDialog = function(url, returnFunc, width, height, strTitle, retFocus) {

    if (strTitle == undefined) {
        strTitle = 'Dialog Window';
    }
    var popup = new _TF.ModalDlg({ 'id': '',
        'width': width, 'height': height,
        'loc': _TF.APP.Enum.locTypes.CEN, 'type': _TF.APP.Enum.contentTypes.iframe, 'modal': true,
        'title': 'Dialog Window', 'URL': url
    });
    popup.show();
};



_TF.APP.Main.openModalDialog = function(idDlg, url, width, height, checkcurrent, strTitle, Loc, returnFunc, retFocus) {
    if (idDlg == null) idDlg = '';
    if (Loc == null) Loc = _TF.APP.Enum.locTypes.N;

    _TF.APP.Global.P_Popup[_TF.APP.Global.P_I] = new _TF.ModalDlg({
        'id': idDlg, 'returnFunc': returnFunc, 'returnFocusID': retFocus,
        'width': width, 'height': height,
        'loc': Loc, 'type': _TF.APP.Enum.contentTypes.iframe, 'modal': true,
        'title': strTitle, 'URL': url
    });
    _TF.APP.Global.P_Popup[_TF.APP.Global.P_I].show();
    _TF.APP.Global.P_I += 1;
};


_TF.APP.Main.CloseAllErrors = function() {
    for (var i = _TF.APP.Global.P_AI; i >= 0; i--) {
        _TF.APP.Main.hideError(i);
    }
    _TF.APP.Global.P_AI = 0;
};

_TF.APP.Main.hideError = function(iter) {
    if (_TF.APP.Global.P_AI > 0) {
        if (_TF.APP.Global.P_Alert[_TF.APP.Global.P_AI - 1] != null) { _TF.APP.Global.P_Alert[_TF.APP.Global.P_AI - 1].hide(_TF.APP.Enum.contentTypes.alert); }
        _TF.APP.Global.P_Alert[_TF.APP.Global.P_AI - 1] = null;
        _TF.APP.Global.P_AI -= 1;
        _TF.APP.Global.P_Alert.length = _TF.APP.Global.P_AI;
    }
};

_TF.APP.Main.closeModalDialog = function(dlgId, dlgIdRefresh) {

    if (dlgId == null) {
        if (_TF.APP.Global.P_I > 0) {
            if (_TF.APP.Global.P_Popup[_TF.APP.Global.P_I - 1] != null) { _TF.APP.Global.P_Popup[_TF.APP.Global.P_I - 1].hide(_TF.APP.Enum.contentTypes.iframe); }
            _TF.APP.Global.P_Popup[_TF.APP.Global.P_I - 1] = null;
            _TF.APP.Global.P_I -= 1;
            _TF.APP.Global.P_Popup.length = _TF.APP.Global.P_I;
        }
    }
    else {
        for (var i = 0; i <= _TF.APP.Global.P_I; i++) {
            if (_TF.APP.Global.P_Popup[i].id == dlgId) {
                if (_TF.APP.Global.P_Popup[i] != null) { _TF.APP.Global.P_Popup[i].hide(_TF.APP.Enum.contentTypes.iframe); }
                _TF.APP.Global.P_Popup[i] = null;
                _TF.APP.Global.P_I -= 1;
            }
        }

    }
};



_TF.APP.Main.DisplayError = function(retFunc, sTask, retFocus) {
    //showAlert(_TF.APP.Global.g_jsErrorType, _TF.APP.Global.g_jsErrorTxt, callBackFunc);
    if (sTask == null) { sTask = "Unknown"; }
    _TF.APP.Global.P_Alert[_TF.APP.Global.P_AI] = new _Dialog({
        'oName': '_TF.APP.Global.P_Alert[' + _TF.APP.Global.P_AI + ']',
        'width': 300, 'height': 700, 'returnFunc': retFunc, 'returnFocusID': retFocus,
        'loc': _TF.APP.Enum.locTypes.NE, 'type': _TF.APP.Enum.contentTypes.alert, 'task': sTask,
        'title': 'Alert!', 'alertType': _TF.APP.Global.g_jsErrorType, 'alertText': _TF.APP.Global.g_jsErrorTxt
    });
    _TF.APP.Global.P_Alert[_TF.APP.Global.P_AI].show();
    _TF.APP.Global.P_AI += 1;
};

_TF.APP.Main.showMsgBox = function(id, sTitle, sQuestion, eType, retFunc, retFocus) {
    //showAlert(_TF.APP.Global.g_jsErrorType, _TF.APP.Global.g_jsErrorTxt, callBackFunc);
    _TF.APP.Global.P_MsgBox = new _Dialog({ 'id': id,
        'width': 300, 'height': 200, 'returnFunc': retFunc, 'returnFocusID': retFocus,
        'loc': _TF.APP.Enum.locTypes.CEN, 'type': _TF.APP.Enum.contentTypes.MsgBox, 'task': 'unknown',
        'title': sTitle, 'msgboxType': eType, 'msgboxQuestion': sQuestion
    });
    _TF.APP.Global.P_MsgBox.show();
};

_TF.APP.Main.showCsMsgBox = function(id, sTitle, sQuestion, eType, retFunc, retFocus) {
    //showAlert(_TF.APP.Global.g_jsErrorType, _TF.APP.Global.g_jsErrorTxt, callBackFunc);
    _TF.APP.Global.P_MsgBox = new _Dialog({ 'id': id,
        'width': 300, 'height': 200, 'returnFunc': retFunc, 'returnFocusID': retFocus,
        'loc': _TF.APP.Enum.locTypes.CEN, 'type': _TF.APP.Enum.contentTypes.csMsgBox, 'task': 'unknown',
        'title': sTitle, 'msgboxType': eType, 'msgboxQuestion': sQuestion
    });
    _TF.APP.Global.P_MsgBox.show();
};

// Page Event Functions
_TF.APP.Main.stdOnUnload = function() { };

_TF.APP.Main.ShowError = function(txtMessage, iType, callBackFunc) {
    _TF.APP.Global.g_jsErrorTxt = txtMessage;
    _TF.APP.Global.g_jsErrorType = iType;
    _TF.APP.Main.DisplayError(callBackFunc);
};

leftPanelKeyboardEvent = function(e) {
    var key;
    if (document.all) { key = event.keyCode; }
    else { key = e.which; }

    switch (key) {
        case 113: //F2
            try { OpenSearchDialog(_TF.APP.Global.SearchPage); }
            catch (ex) { alert("No Search Defined for screen"); }
            event.keyCode = 0; //Stop browser bubble event!
            break;
        case 114:
        case 118:  // F3 F7
            event.keyCode = 0; //Stop browser bubble event!
            break;
        case 18:  //Queue up the key presses - used for scanner purposes
            _TF.APP.Global.pressed_keys = key;
            break;
        case 83:
            _TF.APP.Global.pressed_keys = _TF.APP.Global.pressed_keys + "" + key;
            break;
    }

    if ((key != 18) && (key != 83)) {
        _TF.APP.Global.pressed_keys = "";
    }
    if (_TF.APP.Global.pressed_keys != "") {
        aux = new String(_TF.APP.Global.pressed_keys);
        if ((aux.indexOf('1883') != -1) || (aux.indexOf('171899') != -1)) {
            _TF.APP.Global.pressed_keys = "";
        }
    }
};

// Run on load
//_AddEvent(document, "keydown", leftPanelKeyboardEvent);
//_AddEvent(document, "help", getHelp);

// Session Timeout Functions


_TF.Session.htmlWrite = function() {
    var arrBuf = [];
    arrBuf.push("<table><tr><td>");
    arrBuf.push("<style type=\"text/css\">.container {width:100%; height:100%;display:none;}#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}</style>");
    arrBuf.push("<script type=\"text/javascript\" defer=\"defer\">var timerID = window.setTimeout('ShowLogOffMessage()', 60000);");
    arrBuf.push("var hasRefreshed = false;var cdt;var logOffUrl='/_fw/anon/loggedout.htm';var idletimeoutUrl='/anon/loggedout.htm';");
    arrBuf.push("function HandleRefresh(){hasRefreshed = true;clearTimeout(cdt);clearTimeout(timerID);top._TF.APP.Global.S_Warning.hide(_TF.APP.Enum.contentTypes.html);top._TF.Session.RegisterTimeout(); }");
    arrBuf.push("function Exit(){if(!hasRefreshed){ShowLogOffMessage();}}");
    arrBuf.push("function ShowLogOffMessage(){SessionHide('NormalView');SessionShow('ExpiredView');hasRefreshed=false; location=logOffUrl;}");
    arrBuf.push("function HandleLogOff(){hasRefreshed=false;location=logOffUrl;}");
    arrBuf.push("function SessionHide(id) {  _gE(id).style.display = 'none';}");
    arrBuf.push("function SessionShow(id) { _gE(id).style.display = ''; }");
    arrBuf.push("function ActivateCountDown(strContainerID, initialValue) { _TF.APP.Global.S_CtDn = _gE(strContainerID);if (!_TF.APP.Global.S_CtDn) {alert('count down error: container does not exist: '+strContainerID+'   make sure html element with this ID exists'); return;}SetCountdownText(initialValue);window.setTimeout('CountDownTick()', 1000);}");
    arrBuf.push("function CountDownTick() {if (_TF.APP.Global.S_curSecs <= 0) {return;} SetCountdownText(_TF.APP.Global.S_curSecs-1);cdt=window.setTimeout('CountDownTick()', 1000);} ");
    arrBuf.push("function SetCountdownText(seconds) {_TF.APP.Global.S_curSecs = seconds; var minutes=parseInt(seconds/60); seconds = (seconds%60);var hours=parseInt(minutes/60);minutes = (minutes%60);var strText = AddZero(hours) + ':' + AddZero(minutes) + ':' + AddZero(seconds); _TF.APP.Global.S_CtDn.innerHTML = strText;}");
    arrBuf.push("function AddZero(num) { return ((num >= 0)&&(num < 10))?'0'+num:num+'';}");
    arrBuf.push("window.setTimeout('ActivateCountDown(\"CountDownPanel\", 60)', 1000);</script>");
    arrBuf.push("</td></tr></table>");
    arrBuf.push("<table id='NormalView' style='display:block;' class='container'>");
    arrBuf.push("<tr><td align='center'>Time remaining: <span id='CountDownPanel'></span></td></tr>");
    arrBuf.push("<tr><td align='center' class='bodyTextBold'> -- ");
    arrBuf.push("Your online session will expire in approximately one minute.<br/>Click \"OK\" to continue your online session or click \"Log Off\"<br/>to end your session now.");
    arrBuf.push("</td></tr><tr><td align='center' class='tanButtonRow'>");
    arrBuf.push("<input type='button' id='btnOK' value='&nbsp;&nbsp;OK&nbsp;&nbsp;' class='buttonFwd' onClick='javascript:HandleRefresh();'>");
    arrBuf.push("<input type='button' id='btnLogOff' value='Log Off' class='buttonFwd' onclick='javascript:window.setTimeout(\"HandleLogOff();\",100);'>");
    arrBuf.push("</td></tr></table><table id='ExpiredView' class='container'><tr><td class='spacerH5'>&nbsp;</td></tr><tr>");
    arrBuf.push("<td rowspan='3' class=spacerW20>&nbsp;</td><td align='center' class='bodyTextBold'>");
    arrBuf.push("<br><img src='/_fw/images/clock.gif' alt='clock'  align='absmiddle'>&nbsp;Your online session has expired.<br>");
    arrBuf.push("<br><br></td><TD rowspan='3' class=spacerW20>&nbsp;</TD></tr><tr><td><div class='dashes'>&nbsp;</div></td></tr>");
    arrBuf.push("<tr><td align='center' class='tanButtonRow'>");
    arrBuf.push("<INPUT type='button'  value='&nbsp;&nbsp;OK&nbsp;&nbsp;' class='buttonFwd' onclick='javascript:window.setTimeout(\"HandleLogOff();\",100);'>");
    arrBuf.push("</td></tr><tr><td class='spacerH10'>&nbsp;</td></tr></table>");
    return arrBuf.join("");
};

_TF.Session.FireWarning = function() {
    _TF.APP.Global.S_Warning = new _Dialog({
        'oName': '_TF.APP.Global.S_Warning',
        'id': 'timeout', 'returnFunc': null, 'returnFocusID': null,
        'width': 578, 'height': 185, 'showClose': false,
        'loc': _TF.APP.Enum.locTypes.CEN, 'type': _TF.APP.Enum.contentTypes.html, 'modal': true,
        'title': 'Session Timeout', 'HTML': _TF.Session.htmlWrite()
    });

    _TF.APP.Global.S_Warning.show();
};

//Used to keep sessions alive
_TF.Session.keepMeAlive = function(imgName) {
    myImg = _gE(imgName);
    if (myImg) { myImg.src = myImg.src.replace(/\?.*$/, '?' + Math.random()); }
};

_TF.Session.RegisterTimeout = function(minutes) {
    ///<summary>Registers the timeout code for login/session</summary>
    ///<param name="minutes">The number of minutes of idle time before the session timesout.</param>
    ///<returns>Encoded HTML</returns>
    if (minutes == undefined) { minutes = _TF.APP.Global.S_Timeout; }
    _TF.APP.Global.S_msTillPopup = (minutes * 60) * 1000;
    if (_TF.APP.Global.g_iSTimeOut != undefined) { window.clearTimeout(_TF.APP.Global.g_iSTimeOut); }
    _TF.APP.Global.g_iSTimeOut = window.setTimeout('_TF.Session.FireWarning()', _TF.APP.Global.S_msTillPopup);
    _TF.Session.keepMeAlive('keepMeAlive');
};

//------------------ tfNLog functions

_TF.Util.NLog = function() {
    bPersistState = true;
    // Namespacing
    var sNamespace = "tf_log";
    var sInstance = "tfNLog";
    var sDOMInstance = sNamespace + "_" + sInstance;
    var Config_Enabled = true;
    //    if (Config_Enabled == false && location.href.match(/edNlog/)) { Config_Enabled = true; }
    var bLoggerConfigured = false;
    var nNumMsgsLogged = 0;

    // Public Methods

    this.debug = function(msg, stsk) { logMsg("DEBUG", msg, stsk); };
    this.info = function(msg, stsk) { logMsg("INFO", msg, stsk); };
    this.warning = function(msg, stsk) { logMsg("WARN", msg, stsk); };
    this.error = function(msg, stsk) { logMsg("ERROR", msg, stsk); };

    // This method toggles the on-screen display div on or off as needed
    this.toggleDisplay = function() {
        var oBody = _gE(sDOMInstance + '_body');
        if (oBody.style.display == 'none') { oBody.style.display = 'block'; } else { oBody.style.display = 'none'; }
        if (bPersistState) { _TF.Cookie.setCookie(sInstance + "_visibility", oBody.style.display); }
    };

    // this function clears the on-screen display
    this.clearLog = function() {
        _gE(sDOMInstance + '_logDisplay').innerHTML = '';
        nNumMsgsLogged = 0;
        _gE(sDOMInstance + '_handle').innerHTML = nNumMsgsLogged + ": Msgs";
    };

    this.enable = function() {
        if (!bLoggerConfigured) { initializeDisplay(); }
    };

    //	Public method to set any amount of text into the text area in the footer
    this.text = function(sText) { _gE(sDOMInstance + "_textArea").value = sText; };
    //	Public method to try to get the innerHTML of the element identified in the text input box, and place it into the clipboard from view.


    /*------------------------------------------------------------------------------------
    Private Methods
    ------------------------------------------------------------------------------------*/

    //This function logs a message. All the level-specific methods (logger.debug, etc.) turn around and call this methods
    function logMsg(level, msg, stsk) {
        if (Config_Enabled) {
            // increase the count in the handle
            nNumMsgsLogged += 1;
            _gE(sDOMInstance + '_handle').innerHTML = nNumMsgsLogged + ": Msgs";
            // Append the log to a display div so it can be seen right away
            var oDisplay = _gE(sDOMInstance + '_logDisplay');
            if (oDisplay.childNodes.length == 0) { oDisplay.appendChild(createDisplayRow(level, msg, stsk)); }
            else { oDisplay.insertBefore(createDisplayRow(level, msg, stsk), oDisplay.childNodes[0]); }
        } // end of is config enabled
    }

    // this private method creates the row to add the the display div. It generates what actually gets shown 
    // in the appropriate div each time there's a logged event
    function createDisplayRow(sLevel, sMsg, sTsk) {

        var oRes = document.createElement("div");
        oRes.className = "nlRow";
        if (nNumMsgsLogged / 2 != Math.floor(nNumMsgsLogged / 2)) {
            oRes.style.backgroundColor = "#F6F6F6";
        }

        (sTsk != undefined) ? sTsk = " - " + sTsk : sTsk = "";

        var oSev = document.createElement("div");
        oSev.className = "Sev " + sLevel;

        oSev.appendChild(document.createTextNode(sLevel + sTsk));
        oRes.appendChild(oSev);
        var oTime = document.createElement("span");
        oTime.style.paddingLeft = "3px";
        oTime.style.paddingRight = "8px";
        oTime.appendChild(document.createTextNode(getCurrentTimeFormatted()));
        oRes.appendChild(oTime);
        oRes.appendChild(document.createTextNode(sMsg));

        var oClear = document.createElement("div");
        oClear.style.clear = "both";
        oRes.appendChild(oClear);

        return oRes;
    }

    // this private method returns the current date formated properly with a nice AM/PM
    function getCurrentTimeFormatted() {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();
        var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
        if (timeValue == "0") timeValue = 12;
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
        timeValue += (hours >= 12) ? " PM" : " AM";

        return timeValue;
    }

    if (Config_Enabled) { initializeDisplay(); }

    // Initialization code. It's wrapped in a try-catch block because if something here fails, there is no other notification

    function initializeDisplay() {
        if (!bLoggerConfigured) {
            // Create the display div if necessary. This writes directly to the document to create the UI for the logger.
            // Note also that there are onclick events here, which call back to the public methods of the class.
            try {
                // default positions if other positions are not available
                var nTop = 2;
                var nRight = 320;
                var sDisplay = "none";

                if (bPersistState) {
                    try {
                        var sPersistString = _TF.Cookie.getCookie(sInstance + "_position");
                        if (sPersistString != null) {
                            var aTemp = sPersistString.split("|");
                            if (!isNaN(parseInt(aTemp[0]))) {
                                nLeft = aTemp[0];
                            }
                            if (!isNaN(parseInt(aTemp[1]))) {
                                nTop = aTemp[1];
                            }
                        }

                        if (_TF.Cookie.getCookie(sInstance + "_visibility") == "block") { sDisplay = "block"; }
                    } catch (e) {
                        // nullop, just leave the arguments as the default
                    }
                } // end if bPersistState

                var sIdToInspect = _TF.Cookie.getCookie(sInstance + "_idToInspect");
                sIdToInspect = sIdToInspect == null ? "" : sIdToInspect;
                var sB = [];
                sB.push('<div id="');
                sB.push(sDOMInstance);
                sB.push('_container" class="nlCont" style="top:');
                sB.push(nTop);
                sB.push('px; right:');
                sB.push(nRight);
                sB.push('px;"  onmouseover="if(_TF.Element.really_over(this)){');
                sB.push(sInstance);
                sB.push('.toggleDisplay();}" onmouseout="if(_TF.Element.really_out(this)){');
                sB.push(sInstance);
                sB.push('.toggleDisplay();}">');
                sB.push('<div id="');
                sB.push(sDOMInstance);
                sB.push('_handle" class="nlHandle" >0: Msgs</div>');
                sB.push('<div id="');
                sB.push(sDOMInstance);
                sB.push('_body" class="nlBody" style="display:');
                sB.push(sDisplay);
                sB.push('"><div id="');
                sB.push(sDOMInstance);
                sB.push('_header" class="nlHeader"><span id="');
                sB.push(sDOMInstance);
                sB.push('_clear" class="nlClear" onclick="');
                sB.push(sInstance);
                sB.push('.clearLog()">clear</span></div><div id="');
                sB.push(sDOMInstance);
                sB.push('_logDisplay" class="nlLogDisp"></div><div id="');
                sB.push(sDOMInstance);
                sB.push('_footer" class="nlFooter">get html:<input id="');
                sB.push(sDOMInstance);
                sB.push('_idToInspect" style="font-size:9px; height:18px;" value="');
                sB.push(sIdToInspect);
                sB.push('" size=42/> <span id="');
                sB.push(sDOMInstance);
                sB.push('_go" style="color: blue;" onclick="');
                sB.push(sInstance);
                sB.push('.getHTML()">go</span><textarea id="');
                sB.push(sDOMInstance);
                sB.push('_textArea" style="width:95%; height: 40px; font-size:9px;"></textarea></div></div></div></div>');

                document.write(sB.join(''));
                _gE(sDOMInstance + "_clear").style.cursor = "pointer";
                _gE(sDOMInstance + "_go").style.cursor = "pointer";

                savePos = function(o, pX, pY, ev) {
                    if (o.id == sDOMInstance + "_container") { _TF.Cookie.setCookie(sInstance + "_position", +pX + "|" + pY); }
                };

                //edEnableDrag(sDOMInstance + '_container', null, null, this.savePos);
                bLoggerConfigured = true;
            } catch (e) {
                alert("Code-level error initializing edNLog: " + e.description);
            }
        } // end of initializeDisplay
    }
};

var tfNLog = new _TF.Util.NLog();

_TF.debug = tfNLog.debug;
